package paginator.classes
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.Menu;
	import mx.events.MenuEvent;
	
	import paginator.buttons.FirstBtn;
	import paginator.buttons.LastBtn;
	import paginator.buttons.NextBtn;
	import paginator.buttons.PreviousBtn;
	import paginator.helpers.MenuButtonsCreator;
	/**
	 * This class hold all common properties and methods for 
	 * NextButtonsClass & PreviousButtonsClass 
	 * 
	 * @author Hellix
	 */
	public class ButtonsClass
	{
		//---------------------------------------------------------------
		// <------ PROTECTED & PRIVATE PROPERTIES ------>
		//---------------------------------------------------------------
		//{

		protected var _observer:PaginatorManager;

		protected var _menuManager:MenuButtonsCreator;
		protected var _menuButton:Menu;
		protected var _xPositionMenu:int;
		protected var _yPositionMenu:int;
		
		protected var _arrowBtnHeight:int = 25;
		protected var _isMenuRefresh:Boolean = false;
		
		private var _menuType:String;

		//}
		//---------------------------------------------------------------
		// <------ PUBLIC METHODS ------>
		//---------------------------------------------------------------
		//{
		public function ButtonsClass()
		{
		}
		
		public function setObserver(mainManagerObserver:PaginatorManager):void
		{
			_observer = mainManagerObserver;
		}
		//}
		//---------------------------------------------------------------
		// <------ PROTECTED METHODS ------>
		//---------------------------------------------------------------
		//{
		
		protected function onContextMenuButton(event:Event):void
		{
			if (_menuButton == null || _isMenuRefresh)
			{				
				if (_observer.pages >= 50)
				{
					if (event.type == PreviousBtn.CLICK_SKIPPREVIOUS)
					{
						_menuManager = new MenuButtonsCreator(MenuButtonsCreator.PREVIOUS_MENU);
						_menuType = MenuButtonsCreator.PREVIOUS_MENU;
					}
					else if (event.type == NextBtn.CLICK_SKIPNEXT)
					{
						_menuManager = new MenuButtonsCreator(MenuButtonsCreator.NEXT_MENU);	
						_menuType = MenuButtonsCreator.NEXT_MENU;
					}
					
					_menuButton = _menuManager.creatMenu(_observer.pages, _observer.pageToDisplay);	
					_menuButton.addEventListener(MenuEvent.ITEM_CLICK, onClickMenuItem);
					_isMenuRefresh = false;
				}
			}
		}
		
		protected function onClickMenuItem(event:MenuEvent):void
		{
			var valueJump:int = _observer.selectedPage;
			_observer.offset = event.item.value;
		}
		
		protected function jumpFirstOrLastPage(jumpType:int):void
		{
			_observer.selectLastOrFirstPage(jumpType);
			//_observer.updateElements();
		}
		//}
	}
}